package me.zhengjie.service.impl;

import me.zhengjie.mapper.CountChartDao;
import me.zhengjie.pojo.AskNumEntity;
import me.zhengjie.pojo.CountChartEntity;
import me.zhengjie.pojo.ResultVo;
import me.zhengjie.pojo.WorkNumEntity;
import me.zhengjie.service.CountChartService;
import me.zhengjie.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 描述
 *
 * @Author xulitao
 * @Date 2022/3/12
 * @Version 1.0
 */
@Service
public class CountChartServiceImpl implements CountChartService {

    @Autowired
    private CountChartDao dao;

    // 1-学生纬度 2-老师纬度 3-课程纬度
    @Override
    public ResultVo getScore(String type) {
        ResultVo resultVo = new ResultVo();
        if (StringUtils.isEmpty(type)) {
            resultVo.setMgs("Required field is missing");
            resultVo.setCode("500");
            return resultVo;
        }

        switch (type){
            case "1":
                List<CountChartEntity> scoreByStu = dao.getScoreByStu();
                resultVo.setCode("200");
                resultVo.setMgs("SUCCESS");
                resultVo.setData(scoreByStu);
                return resultVo;
            case "2":
                List<CountChartEntity> scoreByTeacher = dao.getScoreByTeacher();
                resultVo.setCode("200");
                resultVo.setMgs("SUCCESS");
                resultVo.setData(scoreByTeacher);
                return resultVo;
            case  "3":
                List<CountChartEntity> scoreByClass = dao.getScoreByClass();
                resultVo.setCode("200");
                resultVo.setMgs("SUCCESS");
                resultVo.setData(scoreByClass);
                return resultVo;
            default:
                resultVo.setMgs("input error");
                resultVo.setCode("406");
                return resultVo;
        }
    }

    @Override
    public ResultVo getPlayNum() {
        ResultVo resultVo = new ResultVo();
        List<AskNumEntity> playNum = dao.getPlayNum();
        resultVo.setCode("200");
        resultVo.setMgs("SUCCESS");
        resultVo.setData(playNum);
        return resultVo;
    }

    @Override
    public ResultVo getWorkNum(String type) {
        ResultVo resultVo = new ResultVo();
        if (StringUtils.isEmpty(type)) {
            resultVo.setMgs("Required field is missing");
            resultVo.setCode("500");
            return resultVo;
        }

        switch (type){
            case "1":
                List<WorkNumEntity> finishStuNum = dao.getFinishStuNum();
                resultVo.setCode("200");
                resultVo.setMgs("SUCCESS");
                resultVo.setData(finishStuNum);
                return resultVo;
            case "2":
                List<WorkNumEntity> finishTeacherNum = dao.getFinishTeacherNum();
                resultVo.setCode("200");
                resultVo.setMgs("SUCCESS");
                resultVo.setData(finishTeacherNum);
                return resultVo;
            default:
                resultVo.setMgs("input error");
                resultVo.setCode("406");
                return resultVo;
        }
    }
}
